﻿using System.Collections.Generic;
using Jarvis.Server.Workers;
using Ninject.Extensions.Logging;
using Topshelf;

namespace Jarvis.Server
{
    public class JarvisWindowsService:ServiceControl
    {

        private readonly IList<Worker> _workers;

        private readonly ILogger _logger;

        public JarvisWindowsService(ILogger logger,LocatorWorker locatorWorker, StatisticsWorker statisticsWorker, WCFWorker wcfWorker,ActionsWorker actionsWorker)
        {

            _workers=new List<Worker>()
                         {
                             locatorWorker,
                             statisticsWorker,
                             wcfWorker,
                             actionsWorker,
                         };

            _logger = logger;

        }

        #region Implementation of ServiceControl

        public bool Start(HostControl hostControl)
        {
            _logger.Trace("Service Starting");
            foreach (var worker in _workers)
            {
                worker.Start();
            }
            return true;
        }

        public bool Stop(HostControl hostControl)
        {
            _logger.Trace("Service Stopping");
            foreach (var worker in _workers)
            {
                worker.Stop();

            }
            return true;
        }

        #endregion
    }
}
